package siteengineer.demand.view;

import inventory.reports.view.CurrentStockReportView;
import inventory.reports.view.InwardReportView;
import inventory.reports.view.OutwardReportView;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;

import common.controller.IndentController;
import common.controller.IssueSlipController;
import common.view.IndentView;
import common.view.IssueSlipView;

import viewframework.UIFrameWork;

public class DemandMainView extends JPanel implements MouseListener
{
	private JToolBar toolBar;
	private JLabel[] leftMenu;
	private JLabel lblCreateNewIndent;
	private JLabel lblCreateNewIssueSlip;
	private SpringLayout sl;

	public DemandMainView() 
	{
		sl=new SpringLayout();
		setLayout(sl);
		setSize(1050,550);
		
		toolBar = new JToolBar();
		toolBar.setBackground(SystemColor.inactiveCaption);
		toolBar.setBorder(null);
		toolBar.setOrientation(SwingConstants.VERTICAL);
		sl.putConstraint(sl.SOUTH, toolBar, 0, sl.SOUTH, this);
		sl.putConstraint(sl.NORTH, toolBar, 1, sl.NORTH, this);
		sl.putConstraint(sl.WEST, toolBar, 0, sl.WEST, this);
		sl.putConstraint(sl.EAST, toolBar, 180, sl.WEST, this);
		makeLeftMenu();
		addButtonsInToolBar();
		addButtonListener();
		add(toolBar);
	}
	
	private void makeLeftMenu()
	{
		leftMenu=new JLabel[2];
		
		lblCreateNewIndent=new JLabel("Create New Indent",SwingConstants.CENTER);
		lblCreateNewIndent.setPreferredSize(new Dimension(72, 40));
		lblCreateNewIndent.setMinimumSize(new Dimension(180, 40));
		lblCreateNewIndent.setMaximumSize(new Dimension(180, 40));
		lblCreateNewIndent.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		leftMenu[0]=lblCreateNewIndent;
		
		lblCreateNewIssueSlip=new JLabel("Create New Issue Slip",SwingConstants.CENTER);
		lblCreateNewIssueSlip.setPreferredSize(new Dimension(72, 40));
		lblCreateNewIssueSlip.setMinimumSize(new Dimension(180, 40));
		lblCreateNewIssueSlip.setMaximumSize(new Dimension(180, 40));
		lblCreateNewIssueSlip.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		leftMenu[1]=lblCreateNewIssueSlip;
		
		for(int k=0;k<leftMenu.length;k++)
			leftMenu[k].setBorder(null);
	}
	
	private void addButtonsInToolBar()
	{
		toolBar.add(lblCreateNewIndent);
		toolBar.addSeparator();
		toolBar.add(lblCreateNewIssueSlip);
		toolBar.addSeparator();
	}
	
	private void addButtonListener()
	{
		for(JLabel temp:this.leftMenu)
			 temp.addMouseListener(this);
	}

	@Override
	public void mouseClicked(MouseEvent arg0) 
	{
		if(arg0.getSource() instanceof JLabel)
		{
			JLabel label=(JLabel) arg0.getSource();
			
			if(label==lblCreateNewIndent)
			{
				IndentView iv=new IndentView();
				try {
					IndentController cntrl = new IndentController(iv,null);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				UIFrameWork.setReportComponent(sl, iv, this, 2);
			}
				
			if(label==lblCreateNewIssueSlip)
			{
				IssueSlipView isv=new IssueSlipView();
				try {
					IssueSlipController cntrl1 = new IssueSlipController(isv,null);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				UIFrameWork.setReportComponent(sl, isv, this,2);
			}
			
		}
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
}
